package interview;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;

public class Interview {
	
	//------------------------------------------------
		//         JDBC 연결
		//------------------------------------------------
		String driver = "oracle.jdbc.driver.OracleDriver";
		String url = "jdbc:oracle:thin:@127.0.0.1:1521:XE"; 
		String db_user = "hr";
		String db_pwd = "hr";

		Connection conn;
		
		InterviewVo vo;
	
	public Interview(){
	
		try {
			// 1) 드라이버 로딩
			Class.forName(driver).newInstance();
			
			// 2) Connection 객체 생성
			conn = DriverManager.getConnection(url, db_user, db_pwd);
			
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		
	}

	public InterviewVo getVo() {
		return vo;
	}

	public void setVo(InterviewVo vo) {
		this.vo = vo;
	}
	
	public Vector<InterviewVo> list(){

		Vector<InterviewVo> v = new Vector<>();
		
		try{
		// DB 저장
		String sql = "select * from interview where mid like ? or subject like ? or content like ? order by serial desc";
		
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setString(1, "%" + vo.getMid() + "%");
		ps.setString(2, "%" + vo.getSubject() + "%");
		ps.setString(3, "%" + vo.getContent() + "%");
		
		ResultSet rs = ps.executeQuery();
		
		while(rs.next()){
			InterviewVo vo = new InterviewVo();
			
			vo.setMid(rs.getString("mid"));
			vo.setSubject(rs.getString("subject"));
			vo.setContent(rs.getString("content"));
			vo.setSerial(rs.getInt("serial"));
			vo.setMdate(rs.getDate("mdate"));			
			
			v.add(vo);	
		}
		
		rs.close();
		ps.close();
		conn.close();
		
		}catch(Exception ex){
			ex.printStackTrace();
		}
		
		return v;
		
	}
	
	
}
